import { createRouter, createWebHistory } from 'vue-router'
import { authGuard, otherPlatformGuard, questionBankEmitGuard } from './guard'
// 路由的baseURL 需要传递到micro-app，请保持一致。
export const baseURL =
  process.env.NODE_ENV === 'production' ? '/ai-learn-pc' : ''
const router = createRouter({
  history: createWebHistory(baseURL),
  routes: [
    {
      path: '/',
      redirect: '/index'
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/login/Login.vue')
    },
    {
      path: '/pad-graph',
      name: 'pad-graph',
      component: () => import('@/views/pad-graph/Index.vue')
    },
    {
      path: '/singleCorrect1',
      name: 'singleCorrect1',
      meta: {
        title: '单题批改'
      },
      component: () => import('@/views/single-correct/Index.vue')
    },
    {
      path: '/singleCorrect',
      name: 'singleCorrect',
      meta: {
        title: '单题批改'
      },
      component: () => import('@/views/assignment/single-correct/Index.vue')
    },
    {
      path: '/comment',
      name: 'Comment',
      meta: {
        title: '题目讲评'
      },
      component: () => import('@/views/comment/index.vue')
    },
    {
      path: '/comment/studentResponse',
      name: 'StudentResponse',
      meta: { title: '学生作答' },
      component: () => import('@/views/comment/StudentResponse.vue')
    },
    {
      path: '/index',
      name: 'index',
      redirect: '/index/workbench',
      component: () => import('@/views/layout/Index.vue'),
      meta: {
        title: '首页'
      },
      children: [
        {
          path: 'workbench',
          name: 'workbench-route',
          meta: {
            title: '工作台'
          },
          children: [
            {
              path: '',
              name: 'workbench',
              meta: {
                title: '工作台'
              },
              component: () => import('@/views/workbench/Index.vue')
            },
            {
              path: 'userInfo',
              name: 'userInfo',
              meta: {
                title: '个人资料'
              },
              component: () => import('@/views/workbench/UserInfo.vue')
            },
            {
              path: 'classManage',
              name: 'classManage',
              meta: {
                title: '班级管理'
              },
              component: () => import('@/views/workbench/ClassManage.vue')
            }
            // {
            //   path: 'classManage',
            //   name: 'classManage',
            //   meta: {
            //     title: '班级管理'
            //   },
            //   component: () => import('@/views/workbench/ClassManage.vue')
            // }
          ]
        },
        {
          path: 'messageCenter',
          name: 'messageCenter',
          meta: {
            title: '消息中心'
          },
          component: () => import('@/views/message-center/MessageCenter.vue'),
          redirect: {
            name: 'msgList'
          },
          children: [
            {
              name: 'msgList',
              path: 'msgList',
              component: () =>
                import('@/views/message-center/views/MessageList.vue')
            },
            {
              name: 'msgDetail',
              path: 'msgDetail',
              component: () =>
                import('@/views/message-center/views/MessageDetail.vue')
            }
          ]
        },
        {
          path: 'assignment',
          name: 'assignment-route',
          meta: {
            title: '任务中心'
          },
          children: [
            {
              path: '',
              name: 'assignment',
              meta: {
                title: '任务中心'
              },
              component: () => import('@/views/assignment/Index.vue')
            },
            {
              path: 'practiceDetail',
              name: 'practiceDetail',
              meta: {
                title: '错题任务详情'
              },
              component: () =>
                import('@/views/assignment/detail/PracticeDetail.vue')
            },
            {
              path: 'practiceCorrect',
              name: 'practiceCorrect',
              meta: {
                title: '待批改列表'
              },
              component: () => import('@/views/assignment/correct/Index.vue')
            },
            {
              path: 'detailCorrect',
              name: 'detailCorrect',
              meta: {
                title: '批改详情'
              },
              component: () =>
                import('@/views/assignment/correct/CorrectDetail.vue')
            },
            {
              path: 'courseDetail',
              name: 'courseDetail',
              component: () =>
                import('@/views/assignment/detail/CourseDetail.vue'),
              meta: {
                title: '任务详情'
              }
            },
            {
              path: 'taskDetail',
              name: 'taskDetail',
              component: () =>
                import('@/views/assignment/detail/TaskDetail.vue'),
              meta: {
                title: '习题详情'
              }
            },
            {
              path: 'waitDetail',
              name: 'waitDetail',
              meta: {
                title: '待批改列表'
              },
              component: () =>
                import('@/views/assignment/detail/WaitDetail.vue')
            },
            {
              path: 'correct',
              name: 'correct',
              meta: {
                title: '待批改列表'
              },
              component: () => import('@/views/assignment/correct/Index.vue')
            },
            {
              path: 'oneThreeDetail',
              name: 'oneThreeDetail',
              meta: {
                title: '举一反三详情'
              },
              component: () =>
                import('@/views/assignment/one-three/OneThreeDetail.vue')
            },
            {
              path: 'wrongScan',
              name: 'wrongScan',
              meta: {
                title: '错题反扫'
              },
              component: () => import('@/views/assignment/wrong-scan/Index.vue')
            },
            {
              path: 'personWrong',
              name: 'personWrong',
              meta: {
                title: '个性错题'
              },
              component: () =>
                import('@/views/assignment/wrong-scan/PersonWrong.vue')
            },
            {
              path: 'wrongPersonWrong',
              name: 'wrongPersonWrong',
              meta: {
                title: '个性错题'
              },
              component: () =>
                import('@/views/assignment/wrong-scan/WrongPersonWrong.vue')
            }
          ]
        },
        {
          path: 'target-boost',
          name: 'target-boost',
          redirect: '/index/target-boost/target-knowledge-point/overview',
          meta: {
            title: '靶向提升'
          },
          component: () => import('@/views/target-boost/Index.vue'),
          children: [
            {
              path: 'target-error-questions',
              name: 'target-error-questions',
              meta: {
                title: '错题靶向',
                noShowAnimate: true
              },
              component: () =>
                import('@/views/target-boost/target-error-questions/Index.vue')
            },
            {
              path: 'personalize-target',
              name: 'personalize-target',
              meta: {
                title: '个性靶向',
                noShowAnimate: true
              },
              component: () =>
                import('@/views/target-boost/personalize-target/Index.vue')
            },
            {
              path: 'target-knowledge-point',
              name: 'target-knowledge-point',
              meta: {
                title: '知识点靶向',
                noShowAnimate: true
              },
              redirect: '/index/target-boost/target-knowledge-point/overview',
              component: () =>
                import('@/views/target-boost/target-knowledge-point/Index.vue'),
              children: [
                {
                  path: 'overview',
                  name: 'overview',
                  meta: {},
                  component: () =>
                    import(
                      '@/views/target-boost/target-knowledge-point/components/Overview.vue'
                    )
                },
                {
                  path: 'details',
                  name: 'details',
                  meta: {
                    title: '知识点详情',
                    showsReturn: true
                  },
                  component: () =>
                    import(
                      '@/views/target-boost/target-knowledge-point/components/Details.vue'
                    )
                }
              ]
            },
            {
              path: 'student-detail',
              name: 'student-detail',
              meta: {
                title: '学生详情',
                showsReturn: true
              },
              component: () =>
                import(
                  '@/views/target-boost/personalize-target/components/StudentDetail.vue'
                ),
              children: [
                {
                  path: 'student-graph-analyze',
                  name: 'student-graph-analyze',
                  meta: {
                    title: '图谱分析'
                  },
                  component: () =>
                    import(
                      '@/views/target-boost/personalize-target/components/StudentGraphAnalyze.vue'
                    ),
                  children: [
                    {
                      path: 'knowledge-point-detail',
                      name: 'knowledge-point-detail',
                      meta: {
                        title: '知识点详情'
                      },
                      component: () =>
                        import(
                          '@/views/target-boost/personalize-target/components/KnowledgePointDetail.vue'
                        )
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          path: '/question-bank/:page*',
          name: 'QuestionBank',
          component: () => import('@/views/question-bank/Index.vue'),
          meta: { changeNav: '题库系统', noShowGutter: true }
        },
        {
          path: '/situation-report',
          name: 'SituationReport',
          component: () => import('@/views/situation-report/Index.vue'),
          meta: { title: '学情分析' }
        },
        {
          path: '/masteringSituation',
          name: 'MasteringSituation',
          component: () =>
            import('@/views/situation-report/grade/MasteringSituation.vue'),
          meta: { changeNav: '学情分析' }
        },
        {
          path: '/classManage',
          name: 'classManage',
          meta: {
            title: '班级管理',
            noShowAnimate: true
          },
          component: () => import('@/views/class-manage/Index.vue'),
          redirect: '/classManage/administration',
          children: [
            {
              path: 'administration',
              name: 'administration',
              meta: {
                title: '行政班'
              },

              component: () =>
                import('@/views/class-manage/cpns/DetailPage.vue')
            },
            {
              path: 'teaching',
              name: 'teaching',
              meta: {
                title: '班级管理'
              },
              component: () =>
                import('@/views/class-manage/cpns/DetailPage.vue')
            },
            {
              path: 'target',
              name: 'target-route',
              meta: {
                title: '靶向班'
              },

              children: [
                {
                  path: '',
                  name: 'target',

                  component: () =>
                    import('@/views/class-manage/cpns/TargetClass.vue')
                },
                {
                  path: 'detail',
                  name: 'detail',
                  component: () =>
                    import('@/views/class-manage/cpns/DetailPage.vue')
                }
              ]
            }
          ]
        }
      ]
    }
  ]
})
router.afterEach(otherPlatformGuard)
router.afterEach(authGuard)

/**
 * 离开题库相关页面后，需重新打开试题蓝，
 * 由于micro-app切换子应用页面时会偶尔卸载组件重新加载，
 * 不能直接在unmounted周期内直接通知打开试题蓝，
 * 这里在路由守卫加了个方法，如果页面是离开题库的页面，会通知应用重新打开试题蓝。
 */
router.beforeEach(questionBankEmitGuard)

export default router
